﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace Alerts_Administration_2010.classes.views.templates
{
    [Obsolete]
    public class AlertTimeTemplate : AlertViewTemplateBase
    {
        private Panel _panel;
        private DropDownList _days;
        private DropDownList _hours;
        private Label _l  = new Label(); // remove before publish

        protected override System.Web.UI.Control CreateControl()
        {
            _panel = new Panel();
            _days = new DropDownList() { ID = "{DE72A2C6-21FB-464E-9171-834A3A28DA6E}" };
            _hours = new DropDownList() { ID = "{8242E949-4695-40C8-BAC5-614FEFFF9719}" };
            _l.ID = "{28BD97AE-AE8A-4FCA-A01B-A445E00B2556}";

            _panel.Controls.Add(_hours);
            _panel.Controls.Add(_days);
            _panel.Controls.Add(_l);

            return _panel;
        }

        protected override string GetBoundPropertyNames()
        {
            return "AlertTime";
        }

        protected override object GetValue(string p)
        {
            return null;
        }

        protected override void BindControl(DetailsViewItemBLL boundItem)
        {
            for (DateTime dt = new DateTime(2010, 9, 19); dt < new DateTime(2010, 9, 26); dt = dt.AddDays(1))
            {
                var li = new ListItem(dt.DayOfWeek.ToString(), dt.DayOfWeek.ToString());
                if (li.Value == boundItem.AlertTime.DayOfWeek.ToString()) li.Selected = true;
                _days.Items.Add(li);
            }

            for (int i = 0; i < 24; i++)
            {
                var li = new ListItem(((i + 11) % 12 + 1).ToString() + ":00 " + ((i / 12) == 0 ? "AM" : "PM"), i.ToString());
                if (li.Value == boundItem.AlertTime.Hour.ToString()) li.Selected = true;
                _hours.Items.Add(li);
            }
            _l.Text = boundItem.AlertFrequency;
        }
    }
}
